<template>
    <table border="1">
        <tr>
            <td colspan="2" style="text-align:center;font-size:30px;">管理员登录</td>
        </tr>
        <tr>
            <td>管理员</td>
            <td>
                <input type="text" v-model="Info.Name"/>
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="Info.Pwd"/>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center;">
                <input type="button" value="登录" @click="login"/>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import {useRouter} from 'vue-router'
import {useCounterStore} from '../stores/counter.ts'

//创建仓库的实例
const Counter=useCounterStore();

//创建路由的实例
const router=useRouter();

//创建响应式数据
const Info=ref({
    Id:0,
    Name:"",
    Pwd:""
})

//保存数据
const login=()=>{
    axios.get("https://localhost:7205/api/RoomType/Login",{
        params:{
            name:Info.value.Name,
            password:Info.value.Pwd
        }
    })
    .then(res=>{
        if(res.data.Id>0)
        {
            alert("登录成功");
            Counter.UserName=res.data.Name;
            alert(Counter.UserName)
            router.push("/AddRoomType");
        }
        else{
            alert("登录失败");
        }
    })
}
</script>